package com.bjtu.laorenyouhao.laoren.service.impl;

import com.bjtu.laorenyouhao.laoren.feign.LaorenFeignService;
import com.bjtu.laorenyouhao.laoren.utils.RenyuanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bjtu.common.utils.PageUtils;
import com.bjtu.common.utils.Query;

import com.bjtu.laorenyouhao.laoren.dao.LaorenJianhurenDao;
import com.bjtu.laorenyouhao.laoren.entity.LaorenJianhurenEntity;
import com.bjtu.laorenyouhao.laoren.service.LaorenJianhurenService;
import org.springframework.util.StringUtils;


@Service("laorenJianhurenService")
public class LaorenJianhurenServiceImpl extends ServiceImpl<LaorenJianhurenDao, LaorenJianhurenEntity> implements LaorenJianhurenService {

    @Autowired
    private LaorenFeignService laorenFeignService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        String key = (String) params.get("key");
        QueryWrapper<LaorenJianhurenEntity> queryWrapper = new QueryWrapper<LaorenJianhurenEntity>();
        if (StringUtils.hasLength(key)){
            queryWrapper.eq("id",key)
                    .or().eq("laoren_id", RenyuanUtils.getLaorenId(key,laorenFeignService));
        }

        IPage<LaorenJianhurenEntity> page = this.page(
                new Query<LaorenJianhurenEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}